package com.demo.dropdataack.service.common;

import com.alibaba.fastjson.JSONObject;
import com.demo.dropdataack.entity.BpmResponse;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;

/**
 * @author
 */
public class PushDataHelper {


    private static  String url = "https://bts.travelsky.com/gateway/openApi/pushService/bpm/v1";

    @Autowired
    private OkHttpClient okHttpClient ;


    /**
     * 上传数据到航易行
     * @return
     */
    public String  PushData(String token ,String description) {



        String bpmResponse = null;
        MediaType JSON1 = MediaType.parse("application/text; charset=utf-8");
        Request.Builder getBpmRequest = new Request.Builder().url(url).post(RequestBody.create(JSON1, description))
                .header("token", token);
        Call callBpm = okHttpClient.newCall(getBpmRequest.build());
        Response response = null;

            try {
                response = callBpm.execute();
                String data1 = response.body().string();
                BpmResponse bpmResponseBean = JSONObject.parseObject(data1, BpmResponse.class);

                if (bpmResponseBean == null) {
                    return null;
                }
                bpmResponse = bpmResponseBean.getData();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return bpmResponse;
        }
    }

